#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LENGTH 2000

int charsCount(char str[])
{
	int count = 0, i = 0;
	while (str[i] != '\0' )
	{
		count++;
		i++;
	}
	return count;
}

int wordsCount(char str[])
{
	int isInWord = 0;//当前是否处于一个单词里边，0：不是，1：是
	int count = 0;//用来计数
	int i=0;//循环控制变量
	while(str[i] != '\0')
	{
		if (str[i] == ' ')
		{//当前字符是空格
			if (isInWord == 1)
			{//当前的单词已结束，遇到了分界符
				isInWord = 0;
			}
		}
		else
		{//不是空格
			if (isInWord == 0)
			{//进入一个新单词里边
				isInWord = 1;
				count++;
			}
		}
		i++;
	}
	return count;
}

int main()
{
	char str1[]="Founded in 2005  Southwest University  SWU  encompasses Southwest Normal University and Southwest Agricultural University  which share an origin dating back to 1906  The school enjoys a long standing history as its fame through ceaseless strive towards academic innovation and integration with social development  As a member of  211 Project  and  Double First class  universities  SWU has an extensive set of disciplinary categories including philosophy  economics  law  pedagogy  literature  history  science  engineering  agriculture  medicine  management and art  It is especially known for its distinctive teacher education and agricultural education ";

	printf("There are %d characters in the string.\n",charsCount(str1));
	
	printf("There are %d words in the string.\n",wordsCount(str1));

	//right answer: 656, 88
}
